#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;


signed main() {
    freopen("C:\\Users\\lenovo\\Desktop\\1.in", "r", stdin);
    vector<pair<string, string> > v;
    map<string, string> M;
    string s, s2;
    while (cin >> s) {
        if (s == "OK") break;
        cin >> s2;
        M[s] = s2; 
    }
    while (cin >> s) {
        cin >> s2;
        if (M[s] == s2) M[s] = "";
    }
    for (auto i : M) {
        if (i.second != "") {
            cout << i.first << " " << i.second << std::endl;
        }
    }
    return 0;
}